<?php

include('../includes/smarty.php');
include_once('../config.php');

session_start();

$ADMIN = new Admin();
$EMPLOYER = new Employer();

if(isset($_SESSION["id"]))
{
	$row = $ADMIN->validate_admin_session($_SESSION["id"]);
	
	if($row)
	{
		$php = @"		$dg = new C_DataGrid(\"SELECT * FROM wms_admin\", \"username\", \"password\");
						$dg -> display();
				";
		
		//	Show the screen.
		$ADMIN->update_lastvisit($_SESSION["id"]);
		
		//	Get the existing companies.
		$companies = $EMPLOYER->get_companies();
		
		$smarty->assign('title', 		'Admin: User Manager');
		$smarty->assign('path', 		$site);
		$smarty->assign('body', 		'main/admin/users.tpl');
		$smarty->assign('companylist', 	$companies);
		$smarty->assign('message',		'');
		$smarty->assign('grid', $php);
		
		$smarty->display('admin.tpl');
	}
	else
	{
		//	Kill the current session, and show the login screen.
		session_destroy();
		header('Location: ../admin/');
	}
}